package library.service.impl;

import library.config.MySqlSessionFactory;
import library.mapper.BookMapper;
import library.po.Book;
import library.service.BookService;
import org.apache.ibatis.session.SqlSession;

import javax.annotation.Resource;
import java.util.List;

public class BookServiceImpl implements BookService{
    @Resource
    private SqlSession sqlSession;
    private BookMapper bookMapper;

    public BookServiceImpl(){
        sqlSession = MySqlSessionFactory.getSqlSessionInstance();
        bookMapper = sqlSession.getMapper(BookMapper.class);
    }
    public void closeSqlsession(){
        this.sqlSession.close();
    }
    @Override
    public int deleteByIsbn(Integer bookIsbn) {
        return bookMapper.deleteByIsbn(bookIsbn);
    }

    @Override
    public int insert(Book record) {
        return bookMapper.insert(record);
    }

    @Override
    public int insertSelective(Book record) {
        return bookMapper.insert(record);
    }

    @Override
    public Book selectByIsbn(Integer bookIsbn) {
        return bookMapper.selectByIsbn(bookIsbn);
    }

    @Override
    public int updateByIsbnSelective(Book record) {
        return bookMapper.updateByIsbnSelective(record);
    }

    @Override
    public int updateByIsbn(Book record) {
        return bookMapper.updateByIsbn(record);
    }

    @Override
    public String selectBookNameByIsbn(Integer isbn){
        return bookMapper.selectBookNameByIsbn(isbn);
    }

    @Override
    public List<Book> selectAllBooks(){
        return bookMapper.selectAllBooks();
    }

    @Override
    public List<Book> selectBook(String str) {
        return bookMapper.selectBook(str);
    }

    @Override
    public int borrowBook(Integer bookIsbn) {
        return bookMapper.borrowBook(bookIsbn);
    }

    @Override
    public int returnBook(Integer bookIsbn) {
        return bookMapper.returnBook(bookIsbn);
    }

}
